TEMPORALS
Photo by Chris Sansbury on Unsplash
I dream of giving birth to a child who will ask, Mother, what was war?
— Eve Merriam
This example is based on a Graphic Detail report of The Economist from November 8th 2018. As the report indicates, since 2000 the world is more peaceful, an observation well represented in this stacked area chart enriched with timeline data and annotations.
url_root <- "https://raw.githubusercontent.com/UN-AVT/kamino-source/main/sources/0-shared/data/"
url_file_aggregated <- "which-countries-are-most-likely-to-fight-wars/conflict_years_df_region_aggregated.csv"
url_aggregated <- paste0(url_root, url_file_aggregated)
df <- read.csv(url_aggregated, header = TRUE)
head(df, n=10)
url_file_timeline <- "which-countries-are-most-likely-to-fight-wars/conflict_timeline_of_battle_deaths.csv"
url_timeline <- paste0(url_root, url_file_timeline)
df_timeline <- read.csv(url_timeline, header = TRUE, stringsAsFactors = FALSE)
head(df_timeline, n=10)
# Refactor to set stack sort order
df$region <- factor(df$region, levels = c("Europe", "Americas", "Asia", "Africa", "Middle East"))
df
To created the stepped effect, we’ll use geom_bar() at full width with the same color and fill to create a categorical area shape. Using visual variables year, deaths and region
theme_opts <- theme(
text = element_text(family = "inconsolata"),
plot.title = element_text(color = "black", size = 12, face = "bold"),
plot.subtitle = element_text(color = "black", size = 8),
plot.caption = element_text(color = "#555555", size = 8),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
panel.border = element_blank(),
panel.background = element_blank(),
panel.grid.minor = element_blank(), # remove minor gridlines
panel.grid.major.x = element_blank(), # remove x (vertical) gridlines
legend.title = element_blank(), # remove legend title
legend.text = element_text(color = "black", size = 8),
legend.position='top'
)
series_pal <- c("Africa" = "#6fccdc",
"Americas" = "#f2bd48",
"Asia" = "#00597a",
"Europe" = "#e65035",
"Middle East" = "#9b4050")
v1 <- ggplot() +
geom_bar(data = df, aes(x=year, y=deaths, group = region, color = region, fill = region), position="stack", stat="identity", width=1.0) +
scale_x_continuous(breaks=seq(1900, 2020, 10)) +
scale_y_continuous(breaks=seq(0, 250, 50)) + # trans='sqrt'
scale_fill_manual(values = series_pal) +
scale_color_manual(values = series_pal) +
labs( title = "Combat deaths per 100,000 people worldwide",
subtitle = "By nationality, grouped by region",
caption = "Sources: Peace Research Institute Oslo; Uppsala Conflict Data Program; Centre for\nSystemic Peace; Maddison Project Database; iCasualties.org; World Bank; The Economist") +
theme_bw() +
theme_opts
girafe(ggobj = v1, width_svg = 16, height_svg = 9,
options = list(opts_sizing(rescale = TRUE, width = 1.0)))
Now we add the timelines with geom_segment() and include end points and labels to indicate conflict start and end.
df_timeline$mid_year <- (df_timeline$conflict_start_year + df_timeline$conflict_end_year)/2
v2 <- v1 +
geom_segment(data = df_timeline, aes(x = conflict_start_year, y = deaths, xend = conflict_end_year, yend = deaths), colour = "black" ) +
geom_point(data = df_timeline, aes(x = conflict_start_year, y = deaths), colour = "black" ) +
geom_point(data = df_timeline, aes(x = conflict_end_year, y = deaths), colour = "black" ) +
geom_text(data = df_timeline, aes(x = mid_year, y = deaths+3, label = conflict_name), hjust = "center", vjust = 0, color = "#333333", size = 3, fontface = 1, family = "inconsolata" )
girafe(ggobj = v2, width_svg = 16, height_svg = 9,
options = list(opts_sizing(rescale = TRUE, width = 1.0)))
Lastly, some texts to help explain the visual and tell a story.
v3 <- v2 +
annotate("text", x = 1950, y = 90,
label = "> These charts count the deaths of soldiers and civilians caused by\n weapons, in conflicts involving at least one state army and 100\n fatalities. The data include interstate and civil wars. They exclude\n deaths from genocide, terrorism, starvation and disease, such as the\n 500,000-800,000 people who died in the Rwandan genocide of 1994\n and the 1m-5m who died in the Congo war of 1998-2003.",
hjust = "left", vjust = 1, color = "#333333", size = 3, fontface = 1, family = "inconsolata")
girafe(ggobj = v3, width_svg = 16, height_svg = 9,
options = list(opts_sizing(rescale = TRUE, width = 1.0)))